# set compile flags for MSVC

set(CMAKE_C_CXX_COMMON_FLAGS "-fPIC ${SALVIA_GCC_GCOV_PARAM} -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -w -fexceptions -msse2 -mstackrealign")
if(MINGW)
	set(CMAKE_C_CXX_COMMON_FLAGS "${CMAKE_C_CXX_COMMON_FLAGS} -DWIN32 -DWINDOWS")
endif(MINGW)

if(CMAKE_INFO_PLATFORM_BITNESS EQUAL 32)
	set(CMAKE_C_CXX_COMMON_FLAGS "${CMAKE_C_CXX_COMMON_FLAGS} -m32")
	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
	set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m32")
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
	IF(WIN32)
		set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} --target=pe-i386")
	ELSE()
		set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} --target=elf32-i386")
	ENDIF()
else(CMAKE_INFO_PLATFORM_BITNESS EQUAL 32)
	set(CMAKE_C_CXX_COMMON_FLAGS "${CMAKE_C_CXX_COMMON_FLAGS} -m64")
	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m64")
	set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -m64")
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64")
	IF(WIN32)
		set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} --target=pe-x86-64")
	ELSE()
		set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} --target=elf64-x86-64")
	ENDIF()
endif(CMAKE_INFO_PLATFORM_BITNESS EQUAL 32)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_CXX_COMMON_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_CXX_COMMON_FLAGS} -std=c++11")

if (MINGW)
	set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -U__STRICT_ANSI__ -U__NO_ISOCEXT")
endif (MINGW)

set(CMAKE_C_CXX_DEBUG_FLAGS "-D_DEBUG -DDEBUG -g -O0" )
set(CMAKE_C_CXX_RELEASE_FLAGS "-DNDEBUG -O2" )
set(CMAKE_C_CXX_RELWITHDEBINFO_FLAGS "-DNDEBUG -g -O2")
set(CMAKE_C_CXX_MINSIZEREL_FLAGS "-DNDEBUG -Os")

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_C_CXX_DEBUG_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_C_CXX_RELEASE_FLAGS}" )
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_C_CXX_RELWITHDEBINFO_FLAGS}")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} ${CMAKE_C_CXX_MINSIZEREL_FLAGS}")

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_CXX_DEBUG_FLAGS}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_CXX_RELEASE_FLAGS}" )
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} ${CMAKE_C_CXX_RELWITHDEBINFO_FLAGS}")
set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} ${CMAKE_C_CXX_MINSIZEREL_FLAGS}")
